package logic

import (
	"context"
	"house/houseclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseAddLogic) HouseAdd(req *types.HouseAddRequest) (resp *types.Response, err error) {
	// todo: 房源发布
	house, err := l.svcCtx.HouseRpc.CreateHouse(l.ctx, &houseclient.CreateHouseReq{
		City:    req.City,
		Address: req.Address,
		Floor:   req.Floor,
		Size:    float32(req.Size),
		Price:   req.Price,
		Info:    req.Info,
		Status:  req.Status,
		UserId:  req.Price,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "房源发布成功",
		Data: house,
	}, nil
}
